package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EntrpriseInfo;
import com.ruoyi.system.service.IEntrpriseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业信息Controller
 *
 * @author ruoyi
 * @date 2021-11-09
 */
@RestController
@RequestMapping("/system/info")
public class EntrpriseInfoController extends BaseController
{
    @Autowired
    private IEntrpriseInfoService entrpriseInfoService;

    /**
     * 查询企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(EntrpriseInfo entrpriseInfo)
    {
        startPage();
        List<EntrpriseInfo> list = entrpriseInfoService.selectEntrpriseInfoList(entrpriseInfo);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EntrpriseInfo entrpriseInfo)
    {
        List<EntrpriseInfo> list = entrpriseInfoService.selectEntrpriseInfoList(entrpriseInfo);
        ExcelUtil<EntrpriseInfo> util = new ExcelUtil<EntrpriseInfo>(EntrpriseInfo.class);
        return util.exportExcel(list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{entrId}")
    public AjaxResult getInfo(@PathVariable("entrId") Long entrId)
    {
        return AjaxResult.success(entrpriseInfoService.selectEntrpriseInfoByEntrId(entrId));
    }

    /**
     * 新增企业信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EntrpriseInfo entrpriseInfo)
    {
        return toAjax(entrpriseInfoService.insertEntrpriseInfo(entrpriseInfo));
    }

    /**
     * 修改企业信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EntrpriseInfo entrpriseInfo)
    {
        return toAjax(entrpriseInfoService.updateEntrpriseInfo(entrpriseInfo));
    }

    /**
     * 删除企业信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entrIds}")
    public AjaxResult remove(@PathVariable Long[] entrIds)
    {
        return toAjax(entrpriseInfoService.deleteEntrpriseInfoByEntrIds(entrIds));
    }
}
